﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.IO;
using System.Text;
using System.Data;
using EntityLibrary;
using UltimusEikLibrary;

namespace MobileClientBackground
{
    /// <summary>
    /// Ultimus 服务
    /// </summary>
    [WebService(Namespace = "Ultimus 服务接口")]
    [WebServiceBinding(ConformsTo = WsiProfiles.None)]
    [System.ComponentModel.ToolboxItem(false)]

    public class Ultimus_MobileServices : System.Web.Services.WebService
    {
        private UltimusEikOfTask Eik = new UltimusEikOfTask();

        private UltimusEikOfOrgOC OC = new UltimusEikOfOrgOC();

        private UltimusEikOfOther Other = new UltimusEikOfOther();

        private UltimusEikOfDataBase DataBase = new UltimusEikOfDataBase();

        private UltimusEikOfIncident iIncident = new UltimusEikOfIncident();

        private DALLibrary.PageSource Source = new DALLibrary.PageSource();

        [WebMethod(Description = "Ultimus 服务接口 获得新建任务列表")]
        public List<EntityLibrary.Tasks> GetNewTaskListOfUltimusEik(string UserAccount)
        {
            return Eik.GetNewTaskListOfUltimusEik(UserAccount);
        }

        [WebMethod(Description = "Ultimus 服务接口 获得待办任务列表")]
        public List<EntityLibrary.Tasks> GetMyTaskListOfUltimusEik(string UserAccount)
        {
            return Eik.GetMyTaskListOfUltimusEik(UserAccount);
        }

        [WebMethod(Description = "Ultimus 服务接口 获得已办任务列表")]
        public List<EntityLibrary.Tasks> GetCompleteTaskListOfUltimusEik(string UserAccount)
        {
            return Eik.GetCompleteTaskListOfUltimusEik(UserAccount);
        }

        [WebMethod(Description = "Ultimus 服务接口 发起新任务", MessageName = "流程名称 步骤名称 用户账号 发起新任务")]
        public int SendForm(string ProcessName, string StepName, string Summary, string UserAccount, List<VariableInfo> variable, DataSet ds)
        {
            return Source.SavePageDestSource(0, ProcessName, 0, StepName, Summary, UserAccount, variable, ds);
        }

        [WebMethod(Description = "Ultimus 服务接口 发起新任务", MessageName = "任务ID 发起新任务")]
        public int SendForm(string TaskID, string Summary, string UserAccount, List<VariableInfo> variable, DataSet ds)
        {
            Ultimus.WFServer.Task task = new Ultimus.WFServer.Task();
            task.InitializeFromTaskId(TaskID);
            return Source.SavePageDestSource(0, task.strProcessName, 0, task.strStepName, Summary, UserAccount, variable, ds);
        }

        [WebMethod(Description = "Ultimus 服务接口 提交任务", MessageName = "流程名称 实例编号 步骤名称 提交任务")]
        public int Send(string ProcessName, int Incident, string StepName, string UserAccount, string Summary, List<VariableInfo> variable, DataSet ds)
        {
            return Source.SavePageDestSource(0,ProcessName, Incident, StepName, Summary, UserAccount, variable, ds);
        }

        [WebMethod(Description = "Ultimus 服务接口 提交任务", MessageName = "任务ID 提交任务")]
        public int Send(string TaskID, string Summary, List<VariableInfo> variable, DataSet ds)
        {
            Ultimus.WFServer.Task task = new Ultimus.WFServer.Task();
            task.InitializeFromTaskId(TaskID);
            return Source.SavePageDestSource(0, task.strProcessName, task.nIncidentNo, task.strStepName, Summary, task.strUser, variable, ds);
        }

        [WebMethod(Description = "Ultimus 服务接口 退回任务", MessageName = "任务ID 退回任务")]
        public int Return(string TaskID, string Summary, List<VariableInfo> variable, DataSet ds)
        {
            Ultimus.WFServer.Task task = new Ultimus.WFServer.Task();
            task.InitializeFromTaskId(TaskID);
            return Source.SavePageDestSource(1, task.strProcessName, task.nIncidentNo, task.strStepName, Summary, task.strUser, variable, ds);
        }

        [WebMethod(Description = "Ultimus 服务接口 获得在Ultimus Administrator 中的域信息")]
        public string[] GetUltimusByAdministratorDomains()
        {
            return Other.GetDomains();
        }

        [WebMethod(Description = "Ultimus 服务接口 根据 用户账号 密码 效验用户")]
        public UserInfo CheckUserByUltimus(string UserAccount, string PassWord)
        {
            return OC.CheckUser(UserAccount, PassWord);
        }

        [WebMethod(Description = "Ultimus 服务接口 获得所有的流程分类")]
        public List<EntityLibrary.MobileClient_Classification> GetCategoryList()
        {
            return DataBase.GetCategory();
        }

        [WebMethod(Description = "Ultimus 服务接口 获得某个分类下的流程个数")]
        public int GetCategoryCountByCategoryName(string CategoryName)
        {
            return DataBase.GetCountByClassificationInfo(CategoryName);
        }

        [WebMethod(Description = "Ultimus 服务接口 根据行索引获取流程信息")]
        public List<EntityLibrary.MobileClient_Classification> GetProcessInfoByIndex(int index)
        {
            return DataBase.GetProcessInfoByIndex(index);
        }

        [WebMethod(Description = "Ultimus 服务接口 根据 流程名称 实例编号 获得流程监控图")]
        public byte[] GetProcessMonitoring(string ProcessName, int Incident)
        {
            return iIncident.GetProcessMonitoring(ProcessName, Incident);
        }

        [WebMethod(Description = "Ultimus 服务接口 根据 流程名称 实例编号 步骤名称 查询数据")]
        public DataSet GetPageSource(string ProcessName, int nIncident, string StepName)
        {
            return Source.GetPageDestSource(ProcessName, nIncident, StepName);
        }

        [WebMethod(Description = "Ultimus 服务接口 根据 流程名称 实例编号 获取步骤ID")]
        public int GetStepId(string ProcessName, string stepName)
        {
            return Source.GetStepId(ProcessName, stepName);
        }

        [WebMethod(Description = "Ultimus 服务接口 根据 流程名称 实例编号 获取审批列表")]
        public DataSet GetProcessApprovalList(string ProcessName, int Incident)
        {
            return Source.GetProcessApprovalList(ProcessName, Incident);
        }

        [WebMethod(Description = "Ultimus 服务接口 根据 流程名称 获得页面控件配置的数据源")]
        public DataSet GetPageControlSource(string ProcessName,string StepName)
        {
            return Source.GetPageControlSource(ProcessName, StepName);
        }
    }
}
